{extend name="$base" /}
{block name="resources"}
<script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script>
{/block}
{block name="main"}
<table class="mytable">
	<tr>
		<th width="100%">
			<span>下单时间：</span>
			<input type="text" id="startDate" class="input-common middle" placeholder="请选择开始日期" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" />
			&nbsp;-&nbsp;
			<input type="text" id="endDate" placeholder="请选择结束日期" class="input-common middle" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" />
			<span>订单编号：</span>
			<input type="text" id ="out_trade_no" placeholder="交易号" class="input-common middle"/>
			<span>充值用户：</span>
			<input type="text" id ="user_name" placeholder="用户" class="input-common middle"/>
			<button class="btn-common" onclick="LoadingInfo(1)">搜索</button>
		</th>
	</tr>
</table>
<table class="table-class">
	<thead>
		<tr>
			<th align="center">
				<!-- <i class="checkbox-common"><input type="checkbox"  id="check"></i> -->
			</th>
			<th align="left">充值支付交易号</th>
			<th align="left">用户名</th>
			<th align="left">充值金额</th>
			<th align="left">是否支付</th>
			<!-- <th align="left">状态</th> -->
			<th align="center">付款码</th>
			<th align="center">创建时间</th>
			<th align="center">操作</th>
		</tr>
	</thead>
	<tbody></tbody>
</table>
{/block}
{block name="script"}
<script type="text/javascript">
//加载数据
function LoadingInfo(page_index) {
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/Order/rechargeOrderList')}",
		data : {
			"page_index" : page_index,
			"page_size" : $("#showNumber").val(),
			"start_date" : $("#startDate").val(),
			"end_date" : $("#endDate").val(),
			"out_trade_no" : $("#out_trade_no").val(),
			"user_name" : $("#user_name").val()
		},
		success : function(data) {
			if (data["data"].length > 0) {
				$(".table-class tbody").empty();
				for (var i = 0; i < data["data"].length; i++) {
					var html = '';
					html += '<tr align="center">';
						html += '<td></td>';

						var is_pay_str =  "待支付";

						if(data["data"][i]["is_pay"] == 1){
							is_pay_str = "已支付";
						}

					if(data["data"][i]["is_pay"] == -1){
						is_pay_str = "已取消";
					}


						var status_str = "";
						var user_name_str = data["data"][i]["user_name"] == null ? '' : data["data"][i]["user_name"]
						html += '<td align="left">' + data["data"][i]["out_trade_no"] + '</td>';
						html += '<td align="left"><a onclick=view_member('+data["data"][i]["uid"]+')>' + user_name_str + '</a></td>';
						html += '<td align="left" >' + data["data"][i]["recharge_money"] + '</td>';
						html += '<td align="left">' + is_pay_str + '</td>';
						if(data["data"][i]["message"]){
							html += '<td align="left"><div style="width: 300px">'+data["data"][i]["message"]+'</div></td>';
						}else{
							html += '<td align="left">--</td>';
						}

					// html += '<td align="left">' + status_str + '</td>';
						
						html += '<td align="center">' + timeStampTurnTime(data["data"][i]["create_time"]) + '</td>';

					html += '<td align="center">' ;
						if(data["data"][i]["is_pay"] == 0){
							html += '<a onclick="confirm_record('+ data["data"][i]["out_trade_no"]+')">确认</a>';
						}

						if(data["data"][i]["is_pay"] == 0){
							html += '<a onclick="delete_record('+ data["data"][i]["out_trade_no"]+')" style="margin-left: 50px;color: red">取消</a>';
						}


					html += '</td >' ;

					html += '</tr>';
					$(".table-class tbody").append(html);
				}
			} else {
				var html = '<tr align="center"><td colspan="6">暂无符合条件的数据记录</td></tr>';
				$(".table-class tbody").html(html);
			}
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
		}
	});
}


function delete_record(id){
	$( "#dialog" ).dialog({
		buttons: {
			"确定": function() {
				$.ajax({
					type : "post",
					url : "{:__URL('ADMIN_MAIN/Order/rechargeDelete')}",
					data : { "id" : id },
					dataType : "json",
					success : function(data) {
						if(data["code"] > 0 ){
							LoadingInfo(getCurrentIndex(id,'#productTbody'));
							showTip(data["message"],'success');
							$("#chek_all").prop("checked", false);
						}else{
							showTip(data["message"],'error');
						}
					}
				});
				$(this).dialog('close');
			},
			"取消,#e57373": function() {
				$(this).dialog('close');
			},
		},
		contentText:"<span style='color: red;font-size: x-large'>款未收到，确定要删除吗？</span>",
	});
}


let flag = false;
function confirm_record(id){
	$( "#dialog" ).dialog({
		buttons: {
			"确定": function() {

				if(flag == true){
					$(this).dialog('close');
					return;
				}
				flag = true
				$.ajax({
					type : "post",
					url : "{:__URL('ADMIN_MAIN/Order/rechargeConfirm')}",
					data : { "id" : id },
					dataType : "json",
					success : function(data) {
						if(data["code"] > 0 ){
							LoadingInfo(getCurrentIndex(id,'#productTbody'));
							showTip(data["message"],'success');
							$("#chek_all").prop("checked", false);
						}else{
							showTip(data["message"],'error');
						}
					}
				});
				flag = false
				$(this).dialog('close');
			},
			"取消,#e57373": function() {
				$(this).dialog('close');
			},
		},
		contentText:"<span style='color: green;font-size: x-large'>款已收到，确定要通过吗？</span>",
	});
}


</script>
{/block}